package kino.command;

import kino.client.KinoClient;
import kino.common.KinoConstant;

@KinoCommandEnable
public class ExpireCommand extends AbstractKinoCommand{
    @Override
    public String doExecute(KinoClient client, String... argv) {
        if (this.isNumeric(argv[1])) {
            if (!client.getDb().getDict().containsKey(argv[0])) {
                return KinoConstant.KEY_NOT_EXISTS;
            }
            client.getDb().setExpire(argv[0], System.currentTimeMillis() + Long.valueOf(argv[1]) * 1000L);
            return KinoConstant.cone;
        }
        return KinoConstant.KEY_EXPIRE_PARAM_ERR;
    }

    @Override
    public Integer getArgc() {
        return 2;
    }

    @Override
    public String getCommandName() {
        return "expire";
    }

    @Override
    public boolean aofFlag() {
        return true;
    }

    @Override
    public boolean hasExtParam() {
        return false;
    }
}
